//倒计时
(function($) {
	var authClass = '.unit-auth';
	var authBtnClass = '.btn';
	var countTime = 60;
	var CountDown = $.CountDown = $.Class.extend({
		init: function(holder) {
			var self = this;
			if(!holder) {
				throw "构造 countDown 时缺少容器元素";
			}
			self.holder = holder;
			self.btn = $.qsa(authBtnClass, self.holder)[0];
			self.initEvent();
		},
		initEvent: function() {
			var self = this;
			self.btn.addEventListener('tap', function(event) {
				countTime = 60;
				self.count(this);

			});
		},
		count: function() {
			var self = this;
			if(countTime == 0) {
				self.btn.removeAttribute("disabled");
				self.btn.value = "发送验证码";
				countTime = 60;
				return;
			} else {
				self.btn.setAttribute("disabled", true);
				self.btn.value = countTime + "s重发";
				countTime--;
			}
			setTimeout(function() {
				self.count();
			}, 1000);
		}

	});

	$.fn.countDown = function() {
		this.each(function(i, element) {
			if(element.countDown) {
				return;
			}
			element.countDown = new CountDown(element);
		});
		return this[0] ? this[0].countDown : null;
	}

	$.ready(function() {
		$(authClass).countDown();
	});

})(mui);